import type { IResult, IStringMap } from "@/types/common";
import type { IMenu } from "@/types/menu";
import { getMyRoleInfo } from "@/utils/api/role";
import { defineStore } from "pinia";

export const useMenuStore = defineStore("menu", {
  state: () => {
    return {
      menuList: [] as Array<IMenu>,
      permissionInfo: {} as IStringMap
    };
  },
  actions: {
    /* 获取菜单权限信息 */
    getMyRoleInfo<T>(): Promise<IResult<T>> {
      return getMyRoleInfo();
    },
    /* 设置菜单信息 */
    setMenuListInfo(data: Array<IMenu>) {
      this.menuList = data;
    },

    /* 设置权限信息 */
    setPermissionInfo(data: IStringMap) {
      this.permissionInfo = data;
    }
  }
});
